<?php
namespace app\mini\controller\v1\client;
use app\common\logic\CouponLogic;
use app\common\logic\CouponSettingLogic;
use app\common\model\Config;
use app\mini\controller\Common;
use think\Exception;
use think\Request;
use think\response\Json;

class Coupon extends Common
{
    public $CouponLogic;
    public $CouponSettingLogic;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->CouponLogic = new CouponLogic();
        $this->CouponSettingLogic = new CouponSettingLogic();
    }

    /**
     * 优惠券列表
     * @return array
     */
    public function index(): Json
    {

        $res = $this->exception(function () {
            return $this->CouponLogic->index(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 历史优惠券列表
     * @return array
     */
    public function history(): Json
    {

        $res = $this->exception(function () {
            return $this->CouponLogic->history(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 优惠券说明
     * @return array
     */
    public function coupon_explain(): Json
    {
        $res = $this->exception(function () {
            $data = Config::get(24);
            return $data['value'];
        });
        return $this->response($res);
    }


    /**
     * 优惠券待领取列表
     * @return Json
     */
    public function coupon_list()
    {
        $res = $this->exception(function () {
            return $this->CouponSettingLogic->index(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 优惠券领取
     * @return Json
     */
    public function get_coupon()
    {
        $res = $this->exception(function () {
            return $this->CouponLogic->get_coupon(request()->param());
        });
        return $this->response($res);
    }
}